package com.surpassun.emall.util;

import java.util.ListResourceBundle;
import java.util.ResourceBundle;

public class PropsUtil {
	
	//The file path begins from the root classpath and the folders are separated by "." instead of "/"
	private final static String FILE_PATH = "properties.app";

	public static String getString(String key) {
		ResourceBundle rb = getResourceBundle();
		if (Validator.isNotNull(rb)) {
			return rb.getString(key);
		} else {
			return null;
		}
	}
	
	public static String[] getArray(String key) {
		String content = getString(key);
		if (Validator.isNotNull(content) && content.startsWith(StringPool.OPEN_CURLY_BRACE)
				&& content.endsWith(StringPool.CLOSE_CURLY_BRACE)) {
			content = content.substring(1, content.length()-1);
			return content.split(StringPool.COMMA);
		} else {
			return null;
		}
	}
	
	public static boolean containsKey(String key) {
		ResourceBundle rb = getResourceBundle();
		if (Validator.isNotNull(rb)) {
			return rb.containsKey(key);
		} else {
			return false;
		}
	}
	
	private static ResourceBundle getResourceBundle() {
		return ListResourceBundle.getBundle(FILE_PATH);
	}
}
